﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SearchBox.ascx.cs" company="Tobias Lekman">
//   Licensed under Microsoft Public License (Ms-PL). See lekman.codeplex.com/license for more information.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace LekmanCom.Controls
{
    using System;
    using System.Web.UI;

    using Microsoft.Security.Application;

    /// <summary>
    /// Control that allows search inputs and redirects to the search results page.
    /// </summary>
    public partial class SearchBox : UserControl
    {
        #region Methods

        /// <summary>
        /// Called when the search query text has been changed and redirects to the search results page.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The <see cref="System.EventArgs"/> instance containing the event data.
        /// </param>
        protected void OnQueryTextChanged(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.Query.Text))
            {
                return;
            }

            string query = Encoder.UrlEncode(this.Query.Text);
            this.Page.Response.Redirect("/search.aspx?q=" + query);
        }

        #endregion
    }
}